/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vinavac.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Quang <quangtin3@gmail.com>
 */
@Entity
@Table(name = "village")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Village.findAll", query = "SELECT v FROM Village v"),
    @NamedQuery(name = "Village.findById", query = "SELECT v FROM Village v WHERE v.id = :id"),
    @NamedQuery(name = "Village.findByVillageCode", query = "SELECT v FROM Village v WHERE v.villageCode = :villageCode")})
public class Village implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 256)
    @Column(name = "VILLAGE_CODE")
    private String villageCode;
    @JoinColumn(name = "COMMUNE", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Commune commune;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "village")
    private List<Subject> subjectList;

    public Village() {
    }

    public Village(Integer id) {
        this.id = id;
    }

    public Village(Integer id, String villageCode) {
        this.id = id;
        this.villageCode = villageCode;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getVillageCode() {
        return villageCode;
    }

    public void setVillageCode(String villageCode) {
        this.villageCode = villageCode;
    }

    public Commune getCommune() {
        return commune;
    }

    public void setCommune(Commune commune) {
        this.commune = commune;
    }

    @XmlTransient
    public List<Subject> getSubjectList() {
        return subjectList;
    }

    public void setSubjectList(List<Subject> subjectList) {
        this.subjectList = subjectList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Village)) {
            return false;
        }
        Village other = (Village) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getVillageCode() + " of " + getCommune().getCommune();
    }
}
